<?php

namespace app\common\enum;


enum Code: int
{
    case Success = 0;
    case Fail = -1;

    //权限
    case PermissionDenied = -100;
    case AuthNeed = -101;
    case PermissionNeed = -102;
    case TokenNotFound = -103;
    case TokenError = -104;
    case TokenExpire = -105;

    //参数
    case ParamsInvalid = -200;
    case ParamsOverRange = -201;
    case ParamsTypeInvalid = -202;

    //model
    case ModelError = -300;
    case DataNotFound = -301;

    // 客户端问题
    case RequestFail = -700;
    case RequestTimeout = -701;
    case ServerNotFound = -702;
    case ConnectToServerFail = -703;

    // 服务端检查失败
    case CheckFail = -800;
    case Denied = -801;
    case LackArgs = -802;
    case InvalidArgs = -803;

    // 服务端执行过程失败
    case ServerError = -810;
    case NotImplemented = -811;
    case ServerTimeout = -812;
    case ServiceUnavailable = -813;

    //App
    case AppError = -900;
    case ModuleNotFound = -901;
    case ControllerNotFound = -902;
    case ActionNotFound = -903;

    public function msg(): string
    {
        return match ($this) {
            self::Success => '成功',
            self::Fail => '失败',
            self::PermissionDenied => '权限拒绝访问',
            self::AuthNeed => '登录拒绝',
            self::PermissionNeed => '无此权限项',
            self::TokenNotFound => '缺少token',
            self::TokenError => 'token有误',
            self::TokenExpire => 'token过期',
            self::ParamsInvalid => '参数无效',
            self::ParamsOverRange => '无此枚举参数',
            self::ParamsTypeInvalid => '参数类型有误',
            self::ModelError => '模型有误',
            self::DataNotFound => '无此数据项',
            self::RequestFail => '请求失败',
            self::RequestTimeout => '请求超时',
            self::ServerNotFound => '服务未发现',
            self::ConnectToServerFail => '连接服务器失败',
            self::CheckFail => '服务器检查失败',
            self::Denied => '拒绝访问',
            self::LackArgs => '缺少参数',
            self::InvalidArgs => '无效参数',
            self::ServerError => '服务器错误',
            self::NotImplemented => '无此应用',
            self::ServerTimeout => '服务器超时',
            self::ServiceUnavailable => '服务不可用',
            self::AppError => 'App错误',
            self::ModuleNotFound => '无此模块',
            self::ControllerNotFound => '无此控制器',
            self::ActionNotFound => '无此执行方法',
        };
    }
}